"""
通用数据模型
"""

from typing import Optional, Any, List, Generic, TypeVar
from pydantic import BaseModel, Field
import time

T = TypeVar('T')

class StandardResponse(BaseModel):
    """标准响应格式"""
    success: bool
    message: str
    data: Optional[Any] = None
    error: Optional[str] = None
    timestamp: int = Field(default_factory=lambda: int(time.time()))

class PaginatedResponse(BaseModel, Generic[T]):
    """分页响应格式"""
    success: bool = True
    message: str = "获取数据成功"
    data: List[T]
    total: int
    page: int
    page_size: int
    total_pages: int
    timestamp: int = Field(default_factory=lambda: int(time.time()))

class BaseEntity(BaseModel):
    """基础实体模型"""
    id: Optional[int] = None
    created_at: Optional[str] = None
    updated_at: Optional[str] = None
    
    class Config:
        from_attributes = True